#!/bin/sh

if [ $# -lt 3 ]
then
    echo "Usage: parallel_mkfs_and_mount device mountpoint host[,host...]"
    exit 1
fi

DEVICE="$1"
MNTPT="$2"
HOSTS="$3"
HOST1="${HOSTS%%,*}"

echo "Running comaned \"echo y | mkfs -t ocfs2 -N 2 -L ${USER}pooper -C 16384 -b 2048 ${DEVICE} on host \"$HOST1\""
ssh "$HOST1" -l root 'echo y | mkfs -t ocfs2 -N 2 -L '"${USER}"'pooper -C 16384 -b 2048 '"${DEVICE}"
if [ $? = 0 ]
then
    cat <<EOF | dsh -i -w "${HOSTS}" -l root
echo "DLM_DOMAIN allow" > /proc/fs/ocfs2_nodemanager/log_mask
mount -t ocfs2 "${DEVICE}" "${MNTPT}"
echo "DLM_DOMAIN off" > /proc/fs/ocfs2_nodemanager/log_mask
EOF

fi

exit $?
